package com.alibaba.cloud.clinic.config.mq;

import com.alibaba.cloud.clinic.constant.ClinicConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DeadLetterConfig {

    @Bean(ClinicConstant.DEAD_LETTER_QUEUE)
    public Queue deadLetterQueue() {
        return new Queue(ClinicConstant.DEAD_LETTER_QUEUE, true);
    }

    @Bean(ClinicConstant.DEAD_LETTER_EXCHANGE)
    public DirectExchange deadLetterExchange() {
        return new DirectExchange(ClinicConstant.DEAD_LETTER_EXCHANGE, true, false);
    }

    @Bean
    public Binding deadLetterBinding(@Qualifier(ClinicConstant.DEAD_LETTER_QUEUE) Queue queue,  @Qualifier(ClinicConstant.DEAD_LETTER_EXCHANGE) DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ClinicConstant.DEAD_LETTER_ROUTING_KEY);
    }

}
